import requests
import webbrowser
param = {'wd':"莫烦python"}
r = requests.get("http://www.baidu.com/s",params=param)
print(r.url)
# webbrowser.open(r.url)
data = {'firstname': '周', 'lastname': '莫烦'}
r = requests.post('http://pythonscraping.com/pages/files/processing.php', data=data)
print(r.text)

file = {'uploadFile': open('C:\\Users\\Harold\\Pictures\\返校.PNG', 'rb')}
r = requests.post('http://pythonscraping.com/pages/files/processing2.php', files=file)
print(r.text)

# # 登录
# payload = {'username': 'Morvan', 'password': 'password'}
# r = requests.post('http://pythonscraping.com/pages/cookies/welcome.php', data=payload)
# print(r.cookies.get_dict())
# # {'username': 'Morvan', 'loggedin': '1'}
# r = requests.get('http://pythonscraping.com/pages/cookies/profile.php', cookies=r.cookies)
# print(r.text)
# # Hey Morvan! Looks like you're still logged into the site!

"""使用 Session 登录"""
session = requests.Session()
payload = {'username': 'Morvan', 'password': 'password'}
r = session.post('http://pythonscraping.com/pages/cookies/welcome.php', data=payload)
print(r.cookies.get_dict())
# {'username': 'Morvan', 'loggedin': '1'}
r = session.get("http://pythonscraping.com/pages/cookies/welcome.php")
print(r.text)
# Hey Morvan! Looks like you're still logged into the site!